<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1400px">
        <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="时间" prop="date">
                    <el-date-picker v-model="queryParams.date" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px"> </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class="card">
            <el-row :gutter="10" class="mb8">
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table v-loading="loading" :data="tableData" border script>
                <el-table-column label="供应商名称" prop="supply_name" min-width="160">
                    <template slot-scope="scope">
                        <el-tooltip effect="dark" :content="scope.row.supply_link" placement="top">
                                <el-link type="primary" @click="toSupply(scope.row.supply_link)">{{ scope.row.supply_name }}</el-link>
                            </el-tooltip>    
                    </template>
                </el-table-column>
                <el-table-column label="sku信息" prop="sku" min-width="160"></el-table-column>
                <el-table-column label="产品图片" min-width="100">
                    <template slot-scope="scope">
                        <ImageUploadImg v-model="scope.row.product_images" :readOnly="true"></ImageUploadImg>
                    </template>
                </el-table-column>
                <el-table-column label="sku销量" prop="count" min-width="100"></el-table-column>
                <el-table-column label="订单时间" prop="date" min-width="160"></el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        </div>
        </div>
    </el-dialog>
</template>

<script>
import { querySupplySaleInfoList,  } from '@/api/supply'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'SupplySaleInfoDialog',
    components: { },
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            download: false,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],

            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                spu: undefined,
                date: [],
            },
            detailDialog: {
                visible: false,
                data: {},
            },
        }
    },
    computed: {
        title() {
            return `库存列表`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },

    created() {
        this.getList()
    },
    
    methods: {
        toSupply(url) {
            window.open(url, '_blank')
        },

        handleClick() {
            this.getList()
        },

        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
                spu: this.params.spu,
            }
            if (qyparams.date?.length == 2) {
                qyparams.date = [parseTime(qyparams.date[0], 'y-m-d'), parseTime(qyparams.date[1], 'y-m-d')]
            }
            querySupplySaleInfoList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.tableData.map(item => {
                        item.product_images = item.product_images?.replaceAll('\\', '')
                        return { ...item }
                    })
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
    },
}
</script>

<style>
.total-warp {
    font-size: 18px;
    font-weight: bold;
    padding: 8px 0 16px 0;
}
</style>
